package com.rs.game.player.controlers.castlewars;

import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.minigames.CastleWars;
import com.rs.game.player.Equipment;
import com.rs.game.player.controlers.Controler;

public class CastleWarsWaiting extends Controler {


    private int team;

    @Override
    public void start() {
	team = (int) getArguments()[0];
	sendInterfaces();
    }

    // You can't leave just like that!

    public void leave() {
	player.getInterfaceManager().removeOverlay(true);
	CastleWars.removeWaitingPlayer(player, team);
    }

    @Override
    public void sendInterfaces() {
	player.getInterfaceManager().setOverlay(57, true);
    }

    @Override
    public boolean processButtonClick(int interfaceId, int componentId, int slotId, int slotId2, int packetId) {
	if (interfaceId == 387) {
	    if (componentId == 9 || componentId == 6) {
		player.getPackets().sendGameMessage("You can't remove your team's colours.");
		return false;
	    }
	}
	return true;
    }

    @Override
    public boolean canEquip(int slotId, int itemId) {
	if (slotId == Equipment.SLOT_CAPE || slotId == Equipment.SLOT_HAT) {
	    player.getPackets().sendGameMessage("You can't remove your team's colours.");
	    return false;
	}
	return true;
    }

    @Override
    public boolean sendDeath() {
	removeControler();
	leave();
	return true;
    }

    @Override
    public boolean logout() {
	player.setLocation(new WorldTile(CastleWars.LOBBY, 2));
	return true;
    }

    @Override
    public boolean processMagicTeleport(WorldTile toTile) {
	player.getDialogueManager().startDialogue("SimpleMessage", "You can't leave just like that!");
	return false;
    }

    @Override
    public boolean processItemTeleport(WorldTile toTile) {
	player.getDialogueManager().startDialogue("SimpleMessage", "You can't leave just like that!");
	return false;
    }

    @Override
    public boolean processObjectTeleport(WorldTile toTile) {
	player.getDialogueManager().startDialogue("SimpleMessage", "You can't leave just like that!");
	return false;
    }

    @Override
    public boolean processObjectClick1(WorldObject object) {
	int id = object.getId();
	if (id == 4389 || id == 4390) {
	    removeControler();
	    leave();
	    return false;
	}
	return true;
    }

    @Override
    public void magicTeleported(int type) {
	removeControler();
	leave();
    }

    @Override
    public void forceClose() {
	leave();
    }
}
